package com.dingjust.tools.pdf.provider;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class AsianFontProvider extends XMLWorkerFontProvider {

    private final String FONT_PATH;
    private final String BH_FONT_PATH;

    public AsianFontProvider(){
        this.FONT_PATH = "";
        this.BH_FONT_PATH = "";
    }


    public AsianFontProvider(String fontPath,String bhFontPath){
        this.FONT_PATH = fontPath;
        this.BH_FONT_PATH = bhFontPath;

    }


    @Override
    public Font getFont(final String fontName, String encoding, float size, final int style) {
        try {
            BaseFont bfChinese;
            if (fontName.equalsIgnoreCase("simsun") && style >= 1) {
                bfChinese = BaseFont.createFont(this.FONT_PATH, "Identity-H", false);
                return new Font(bfChinese, size, style);
            } else {
                bfChinese = BaseFont.createFont(this.FONT_PATH, "Identity-H", false);
                Font font = new Font(bfChinese, size, style, BaseColor.BLACK);
                return font;
            }
        } catch (Exception var7) {
            return super.getFont(fontName, encoding, size, style);
        }
    }
}